package com.zb.common.po.handler;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.TypeHandler;

import com.zb.common.utils.StringUtil;

@SuppressWarnings("rawtypes")
public class FormatHandler extends BaseTypeHandler implements TypeHandler {

    @Override
    public Object getNullableResult(ResultSet rs, int columnIndex)
            throws SQLException {
        String content = rs.getString(columnIndex);
        return StringUtil.formateContent(content);
    }

    @Override
    public Object getNullableResult(ResultSet rs, String columnName)
            throws SQLException {
        String content = rs.getString(columnName);
        return StringUtil.formateContent(content);
    }

    @Override
    public Object getNullableResult(CallableStatement cs, int columnIndex)
            throws SQLException {
        String content = cs.getString(columnIndex);
        return StringUtil.formateContent(content);
    }

    @Override
    public void setNonNullParameter(PreparedStatement ps, int i,
            Object parameter, JdbcType jdbcType) throws SQLException {
        ps.setString(i, String.valueOf(parameter));
    }
}
